package com.dinetech.ejecutor;

import com.dinetech.dao.GalponAdapter;
import com.dinetech.entidades.Session;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.TextView;

public class SeleccionGalpon extends Activity {

	ListView listViewG;
	private int nivelEvento;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_seleccion_galpon);
		//setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		Bundle in = getIntent().getExtras();
		nivelEvento = in.getInt("Nivel");
		
		listViewG= (ListView) findViewById(R.id.listViewGalpones);		
		Session s = Session.getInstance();
		GalponAdapter adaptador = new GalponAdapter(this, s.getLISTA_GALPONES());
        listViewG.setAdapter(adaptador);	        
        
        listViewG.setOnItemClickListener(new OnItemClickListener(){
		 
	    @Override
	    public void onItemClick(AdapterView<?> listView, View view , int position, long id) {
	    			        		    	
	    	int IdGalpon=(int)(long)id;
	    	
	    	TextView nombGalpon = (TextView)view.findViewById(R.id.txtDescripcionGalpon);

	    	Intent i = new Intent(getApplicationContext(), Eventos.class);	
			i.putExtra("IdGalpon", IdGalpon);	
			i.putExtra("NomGalpon", nombGalpon.getText().toString());
			i.putExtra("NivelEvento", nivelEvento);
			startActivity(i);
	    	finish();
	    }
        });
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.seleccion_galpon, menu);
		return true;
	}

	@Override
	public void finish() {		
		super.finish();
	}


	
	
}
